import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '模板名称',
    dataIndex: 'templateName',
    align: 'center',
  },
  {
    title: '投入品',
    align:"center",
    dataIndex: 'input_dictText'
  },
  {
    title: '用法与用量',
    align:"center",
    dataIndex: 'usageAndDosage'
  },
  {
    title: '作业类型',
    align:"center",
    dataIndex: 'productionOperation_dictText'
  },
  {
    title: '作业工艺说明',
    align:"center",
    dataIndex: 'operationDescription'
  },
  {
    title: '作业开始时间',
    align:"center",
    dataIndex: 'jobStartTime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
  },
  {
    title: '作业周期',
    align:"center",
    dataIndex: 'jobDuration'
  },
  {
    title: '作业工艺',
    align:"center",
    dataIndex: 'jobIntroduce'
  },
  {
    title: '是否临时安排',
    align:"center",
    dataIndex: 'randomJob_dictText'
  },
  {
    title: '计划操作人',
    align:"center",
    dataIndex: 'sysUser',
    customRender: ({ record }) => {
      if (record&&record.sysUser){
        return  record.sysUser.realname
      }
      return '';
    },
  },
  {
    title: '种植计划',
    align:"center",
    dataIndex: 'growPlanId_dictText'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "模板名称",
    field: 'templateName',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: '作业类型',
    field: 'productionOperation',
    component: 'JTreeSelect',
    componentProps: {
      dict: "t_classification,name,id",
      pidField: "pid",
      pidValue: "1689815136974086145",
      hasChildField: "has_child",
    },
  },
  {
    label: '是否临时安排',
    field: 'randomJob',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
      placeholder: '请选择是否临时安排',
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '模板名称',
    field: 'templateName',
    component: 'Input',
  },
  {
    label: '投入品',
    field: 'input',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 't_inputs,name,id',
      placeholder: '请选择投入品',
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择投入品!'},
      ];
    },
  },
  {
    label: '用法与用量',
    field: 'usageAndDosage',
    component: 'Input',
  },
  {
    label: '作业类型',
    field: 'productionOperation',
    component: 'JTreeSelect',
    componentProps: {
      dict: "t_classification,name,id",
      pidField: "pid",
      pidValue: "1689815136974086145",
      hasChildField: "has_child",
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择作业类型!'},
      ];
    },
  },
  {
    label: '作业工艺说明',
    field: 'operationDescription',
    component: 'Input',
  },
  {
    label: '作业开始时间',
    field: 'jobStartTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '请选择作业开始时间',
    },
  },
  {
    label: '作业周期',
    field: 'jobDuration',
    component: 'Input',
  },
  {
    label: '作业工艺',
    field: 'jobIntroduce',
    component: 'Input',
  },
  {
    label: '是否临时安排',
    field: 'randomJob',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
      placeholder: '请选择是否临时安排'
    },
  },
  {
    // todo 需要使用租户用户
    label: '计划操作人',
    field: 'jobby',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sys_user,realname,id',
      placeholder: '请选择作业计划操作人',
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择作业计划操作人!'},
      ];
    },
  },
  {
    label: '种植计划',
    field: 'growPlanId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 't_grow_plan,id,id',
      placeholder: '请选择种植计划',
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择种植计划!'},
      ];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
